***preamble

clear
clear matrix
clear mata
set maxvar 30000

***load data

use "${path}\data\hsbt\hsbt.dta", clear 

***prepare outcomes 

foreach v of varlist  broadcon unifying scirejct prvwrong validalt nodarwin {
recode `v' (1=1) (2=1) (3=0) (4=0) 
}

foreach v of varlist hrsgenev hrscreat {
recode `v' (1=0) (2=0) (3=0) (4=1) (5=1) (6=1) (7=1)
}

recode statesci (1=4) (2=3) (3=2) (4=1)
recode validalt (1.5=1)
recode broadcon (2.5=2)
recode unifying (2.5=2)
recode knowevol (1.5=1) (2.5=2)

***prepare treatments

generate evo_score=.
replace evo_score=20.5 if ST_POSTA=="AL"
replace evo_score=59.1 if ST_POSTA=="AK"
replace evo_score=81.8 if ST_POSTA=="AZ"
replace evo_score=65.9 if ST_POSTA=="AR"
replace evo_score=100 if ST_POSTA=="CA"
replace evo_score=86 if ST_POSTA=="CO"
replace evo_score=59.1 if ST_POSTA=="CT"
replace evo_score=79.5 if ST_POSTA=="DE"
replace evo_score=95.5 if ST_POSTA=="DC"
replace evo_score=16 if ST_POSTA=="FL"
replace evo_score=65.9 if ST_POSTA=="GA"
replace evo_score=75 if ST_POSTA=="HI"
replace evo_score=81.8 if ST_POSTA=="ID"
replace evo_score=81.8 if ST_POSTA=="IL"
replace evo_score=95.5 if ST_POSTA=="IN"
replace evo_score=77.3 if ST_POSTA=="IA"
replace evo_score=95.5 if ST_POSTA=="KS"
replace evo_score=54.5 if ST_POSTA=="KY"
replace evo_score=27.3 if ST_POSTA=="LA"
replace evo_score=68.2 if ST_POSTA=="ME"
replace evo_score=72.7 if ST_POSTA=="MD"
replace evo_score=84.1 if ST_POSTA=="MA"
replace evo_score=79.5 if ST_POSTA=="MI"
replace evo_score=86 if ST_POSTA=="MN"
replace evo_score=5 if ST_POSTA=="MS"
replace evo_score=77.5 if ST_POSTA=="MO"
replace evo_score=75 if ST_POSTA=="MT"
replace evo_score=65.9 if ST_POSTA=="NE"
replace evo_score=77.3 if ST_POSTA=="NV"
replace evo_score=90.9 if ST_POSTA=="NH"
replace evo_score=100 if ST_POSTA=="NJ"
replace evo_score=90.9 if ST_POSTA=="NM"
replace evo_score=68.5 if ST_POSTA=="NY"
replace evo_score=81.8 if ST_POSTA=="NC"
replace evo_score=63.3 if ST_POSTA=="ND"
replace evo_score=86.4 if ST_POSTA=="OH"
replace evo_score=25 if ST_POSTA=="OK"
replace evo_score=82 if ST_POSTA=="OR"
replace evo_score=95.5 if ST_POSTA=="PA"
replace evo_score=81.8 if ST_POSTA=="RI"
replace evo_score=90.9 if ST_POSTA=="SC"
replace evo_score=77.3 if ST_POSTA=="SD"
replace evo_score=54.5 if ST_POSTA=="TN"
replace evo_score=64 if ST_POSTA=="TX"
replace evo_score=81.8 if ST_POSTA=="UT"
replace evo_score=86.4 if ST_POSTA=="VT"
replace evo_score=68.2 if ST_POSTA=="VA"
replace evo_score=86.4 if ST_POSTA=="WA"
replace evo_score=2 if ST_POSTA=="WV"
replace evo_score=63.6 if ST_POSTA=="WI"
replace evo_score=evo_score/100
label variable evo_score "Evolution Score"

***prepare controls

foreach var of varlist yrsteach-knowevol {
gen missing_`var'=0
replace missing_`var'=1 if `var'==.
}

foreach var of varlist subjsced-subjeduc {
recode `var' (1=2) (2=1)

gen no_`var'=0
replace no_`var'=1 if `var'==0

gen minor_`var'=0
replace minor_`var'=1 if `var'==1

gen major_`var'=0
replace major_`var'=1 if `var'==2
}

gen low_credhrs=0
replace low_credhrs=1 if credhrs==1

gen medium_credhrs=0
replace medium_credhrs=1 if credhrs==2

gen high_credhrs=0
replace high_credhrs=1 if credhrs==3

gen highest_credhrs=0
replace highest_credhrs=1 if credhrs==4

gen no_crsevol=0
replace no_crsevol=1 if crsevol==0

gen yes_crsevol=0
replace yes_crsevol=1 if crsevol==1

generate division=.
replace division=6 if ST_POSTA=="AL"
replace division=9 if ST_POSTA=="AK"
replace division=8 if ST_POSTA=="AZ"
replace division=7 if ST_POSTA=="AR"
replace division=9 if ST_POSTA=="CA"
replace division=8 if ST_POSTA=="CO"
replace division=1 if ST_POSTA=="CT"
replace division=5 if ST_POSTA=="DE"
replace division=5 if ST_POSTA=="DC"
replace division=5 if ST_POSTA=="FL"
replace division=5 if ST_POSTA=="GA"
replace division=9 if ST_POSTA=="HI"
replace division=8 if ST_POSTA=="ID"
replace division=3 if ST_POSTA=="IL"
replace division=3 if ST_POSTA=="IN"
replace division=4 if ST_POSTA=="IA"
replace division=4 if ST_POSTA=="KS"
replace division=6 if ST_POSTA=="KY"
replace division=7 if ST_POSTA=="LA"
replace division=1 if ST_POSTA=="ME"
replace division=5 if ST_POSTA=="MD"
replace division=1 if ST_POSTA=="MA"
replace division=3 if ST_POSTA=="MI"
replace division=4 if ST_POSTA=="MN"
replace division=6 if ST_POSTA=="MS"
replace division=4 if ST_POSTA=="MO"
replace division=8 if ST_POSTA=="MT"
replace division=4 if ST_POSTA=="NE"
replace division=8 if ST_POSTA=="NV"
replace division=1 if ST_POSTA=="NH"
replace division=2 if ST_POSTA=="NJ"
replace division=8 if ST_POSTA=="NM"
replace division=2 if ST_POSTA=="NY"
replace division=5 if ST_POSTA=="NC"
replace division=4 if ST_POSTA=="ND"
replace division=3 if ST_POSTA=="OH"
replace division=7 if ST_POSTA=="OK"
replace division=9 if ST_POSTA=="OR"
replace division=2 if ST_POSTA=="PA"
replace division=1 if ST_POSTA=="RI"
replace division=5 if ST_POSTA=="SC"
replace division=4 if ST_POSTA=="SD"
replace division=6 if ST_POSTA=="TN"
replace division=7 if ST_POSTA=="TX"
replace division=8 if ST_POSTA=="UT"
replace division=1 if ST_POSTA=="VT"
replace division=5 if ST_POSTA=="VA"
replace division=9 if ST_POSTA=="WA"
replace division=5 if ST_POSTA=="WV"
replace division=3 if ST_POSTA=="WI"

global basic_controls "gender i.age i.yrsteach"
global undergraduate_controls "medium_credhrs high_credhrs highest_credhrs missing_credhrs yes_crsevol missing_crsevol minor_subjsced major_subjsced missing_subjsced minor_subjbio major_subjbio missing_subjbio minor_subjoth major_subjoth missing_subjoth minor_subjstat major_subjstat missing_subjstat minor_subjeduc major_subjeduc missing_subjeduc"
global degree_controls "tchcert degassoc degba degbs degmsed degmssc degphded degphdsc"
global continuing_education_controls "noteadd scitvmag websites scijourn scicours"
global evolution_controls "i.devhuman i.knowevol"
global assessment_test "i.statetst"
global geographic_controls "i.division"

***prepare sample and save data

drop if gender==. | age==. | yrsteach==.

save "${path}\data\hsbt\hsbt_ready.dta", replace